<?php
require_once 'PHPUnit/Framework.php';
require_once 'config/config.php';
require_once 'OBoard/Page.php';
require_once 'OBoard/Finder.php';

class DBPageFinder extends PageFinder {
	function getPDO() {
		return new PDO(CONFIG_TEST_DB_DNS, CONFIG_DB_USER, CONFIG_DB_PASSWORD);
	}
	public function __construct($boardName) {
		$this->boardName = $boardName;
	}
	public function getByNumber($num) {
		$db = $this->getPDO();
		$page = new Page();
		$stmt = $db->prepare("select * from {$this->boardName} where num=:num");
		$stmt->bindParam('num',$num);
		$stmt->execute();
		$row = $stmt->fetch();

		$page->setData($row); //$page->data = $row
		$db = null;
		return $page;
	}
	public function getListByPeriod($startDate, $endDate, $count = 20) {}
}
class DBFinderTest extends PHPUnit_Framework_TestCase {
	function setUp() {
		$this->page_finder = new DBPageFinder('ob1');
	}
	function testOnePage() {
		$page_finder = $this->page_finder;
		$page = $page_finder->getByNumber(1);
		$this->assertEquals('guest', $page->loginId );
	}
	function testPageList() {
		$this->fail();
	}
}
?>
